<?php

namespace App\Http\Controllers\Admin;

use App\Models\Users;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function index()
    {
        $users = Users::all();
        return view('admin.user.index')->with(compact('users'));
    }

    public function create()
    {
        return view('admin.user.create');
    }

    public function store(Request $request)
    {
        Users::create([
            'name' => $request->name,
            'ip' => $request->ip_user,
            'status' => 1,
            'account' => $request->account,
            'create_time' => date('Y-m-d H:i:s'),
        ]);
        return back()->with('msg', '添加成功');
    }

    public function update(Request $request)
    {
        $user = Users::find($request->id);
        return view('admin.user.update')->with(compact('user'));
    }

    public function edit(Request $request)
    {
        $user = Users::find($request->id);
        if (empty($user)) {
            return back()->with('error', '没有这个用户');
        }
        $user->status = $request->status;
        $user->account = $request->account;
        $user->name = $request->name;
        $user->ip = $request->ip_user;
        $user->save();
        return back()->with('msg', '修改成功');
    }

    public function delete(Request $request)
    {

    }

    public function update_status(Request $request)
    {

    }
}
